package com.wy.system.service.impl;

import java.util.List;

import com.wy.common.annotation.DataScope;
import com.wy.common.utils.SecurityUtils;
import com.wy.system.domain.vo.SysHouseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import com.wy.system.mapper.SysHouseMapper;
import com.wy.system.domain.SysHouse;
import com.wy.system.service.ISysHouseService;

/**
 * 房产信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-02
 */
@Service
@Primary
public class SysHouseServiceImpl implements ISysHouseService 
{
    @Autowired
    private SysHouseMapper sysHouseMapper;

    /**
     * 查询房产信息
     * 
     * @param id 房产信息主键
     * @return 房产信息
     */
    @Override
    public SysHouseVo selectSysHouseById(Long id)
    {
        return sysHouseMapper.selectSysHouseById(id);
    }

    /**
     * 查询房产信息列表
     * 
     * @param sysHouse 房产信息
     * @return 房产信息
     */
    @Override
    @DataScope(userAlias = "u")
    public List<SysHouseVo> selectSysHouseList(SysHouse sysHouse)
    {
        return sysHouseMapper.selectSysHouseList(sysHouse);
    }

    /**
     * 新增房产信息
     * 
     * @param sysHouse 房产信息
     * @return 结果
     */
    @Override
    public int insertSysHouse(SysHouse sysHouse)
    {
        return sysHouseMapper.insertSysHouse(sysHouse);
    }

    /**
     * 修改房产信息
     * 
     * @param sysHouse 房产信息
     * @return 结果
     */
    @Override
    public int updateSysHouse(SysHouseVo sysHouse)
    {
        //查询用户通过nickName
        SysUser user=new SysUser();
        user.setNickName(sysHouse.getNickName());
        List<SysUser> sysUsers = sysUserMapper.selectUserList(user);
        Long userId=1L;
        if (sysUsers!=null){
            SysUser user1 = sysUsers.get(0);
            userId= user1.getUserId();
        }
        //继承所有数据
        SysHouse house=new SysHouse();
        house.setId(sysHouse.getId());
        house.setUser(userId);
        house.setSize(sysHouse.getSize());
        house.setLocation(sysHouse.getLocation());
        house.setOrient(sysHouse.getOrient());
        house.setStatus(sysHouse.getStatus());
        house.setPayStatus(sysHouse.getPayStatus());
        return sysHouseMapper.updateSysHouse(house);
    }

    /**
     * 批量删除房产信息
     * 
     * @param ids 需要删除的房产信息主键
     * @return 结果
     */
    @Override
    public int deleteSysHouseByIds(Long[] ids)
    {
        return sysHouseMapper.deleteSysHouseByIds(ids);
    }

    /**
     * 删除房产信息信息
     * 
     * @param id 房产信息主键
     * @return 结果
     */
    @Override
    public int deleteSysHouseById(Long id)
    {
        return sysHouseMapper.deleteSysHouseById(id);
    }
}
